package graphroute

import (
	"power/core/dao/graphdao"
	"power/core/localwrap"
	"power/core/service/graphs"
	"power/http/routes"

	"github.com/RocksonZeta/irisx"
	"github.com/kataras/iris/v12"
)

var logGraphFields = localwrap.GetLogger().Fork("power/http/graphroute", "RouteGraphFields")

//Route{serviceName}
func RouteGraphFields(party iris.Party) {
	party.Get("/", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		id := c.CheckQuery("id").NotEmpty().Int(0)
		uid := c.GetUidInt()
		logGraphFields.Debug().Str("path", c.Path()).Int("id", id).Int("uid", uid).Send()
		r := graphs.GraphFields{}.Get(id)
		c.Ok(r)
	})
	party.Get("/list", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		uid := c.GetUidInt()
		logGraphFields.Debug().Str("path", c.Path()).Int("uid", uid).Send()
		// r := graphs.GraphFields{}.ListByUid(uid)
		// c.Ok(r)
	})
	party.Post("/update", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		var param graphdao.GraphFieldsUpdateParam
		param.Id = c.CheckBody("id").NotBlank().Int(0)
		// param.Name = c.CheckBody("name").NotBlank().String()
		logGraphFields.Debug().Str("path", c.Path()).Interface("param", param).Send()
		routes.Check(c)
		graphs.GraphFields{}.Update(param)
		c.Ok(nil)
	})
	party.Post("/delete", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		id := c.CheckBody("id").NotBlank().Int(0)
		logGraphFields.Debug().Str("path", c.Path()).Int("uid", c.GetUidInt()).Send()
		routes.Check(c)
		graphs.GraphFields{}.Delete(id)
		c.Ok(nil)
	})
}
